#ifndef Socket_class
#define Socket_class

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <string>
#include <arpa/inet.h>
#include "Logger.h"
#include <errno.h>

//http://pubs.opengroup.org/onlinepubs/009604599/functions/setsockopt.html

const int MAXHOSTNAME = 200;
const int MAXCONNECTIONS = 100;
const int MAXRECV = 2048;
extern int errno;
//const int MSG_NOSIGNAL = 0; // defined by dgame

class Socket {


protected:
	Logger* logger;
	int m_sock;
	sockaddr_in m_addr;

public:
	Socket();
	virtual ~Socket();

	// Server initialization
	bool create();
	bool bind(const int port);
	bool listen() const;
	bool accept(Socket&) const;

	void closeSock();

	// Client initialization
	bool connect(const std::string host, const int port);

	// Data Transimission
	bool send(const std::string) const;
	int recv(std::string&) const;

	void set_non_blocking(const bool);

	bool is_valid() const {
		return m_sock != -1;
	}


};

#endif
